/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { BaseElement, element } from '../../BaseElement';

@element('rectangle-canvas-element')
export class RectangleCanvasElement extends BaseElement {
  private rectangleCanvas: any;
  private tip: any;

  static get observedAttributes() {
    return ['text', 'height', 'width'];
  }

  get text() {
    return this.getAttribute('text') || '';
  }

  set text(text: string) {
    this.setAttribute('text', text);
  }

  get height() {
    return this.getAttribute('height') || '';
  }

  set height(height: string) {
    this.setAttribute('height', height);
  }

  initHtml(): string {
    return `
        <style>
        /*
         * Outer box style
         */
        :host{ 
            display: block;
            width: 100%;
            height: 100%;
            position: relative;
            background: background: var(--dark-background3,#FFFFFF);
        }
        
        .config-div {
           width: 80%;
           display: contents;
           flex-direction: column;
           gap: 15px;
        }
        
         #tip {
            max-width: 400px;
            position: absolute;
            display: none;
            z-index: 100;
            background: rgba(255, 255, 255, 1);
            border: 1px solid #F1F2F3;
            border-radius: 2px;
            padding: 2px 4px;
            box-shadow: 1px 1px 8px 1px #4b4b4b;
        }
        
        .legend {
            font-family: Consolas;
            font-size: 16px;
            border-radius: 16px;
            background: #CCC;
            padding: 4px 12px;
            color: white;
            margin: 5px;
            display: inline-block;
        }
        </style>
        <div id='custom-div'>
                 <div class="col-8 mx-auto text-center">
                    <canvas id="treemap" width="1300" height="720">
                        <!-- 替换内容 -->
                        <p>An Tree Map</p>
                    </canvas>
                 </div>
                 <div id="tip">
                    <p><span id="label"></span></p>
                    <p id="value">Value:&nbsp;<span></span></p>
                 </div>
                 <div class="config-div">
                    <div id="legendContainer">
                    </div>
                 </div>
          </div>
            `;
  }

  initElements(): void {
    this.rectangleCanvas = this.shadowRoot?.querySelector('#treemap');
    this.tip = this.shadowRoot?.querySelector('#tip');
  }

  attributeChangedCallback(name: string, oldValue: string, value: string) {
    switch (name) {
    }
  }
}
